//import axios from 'axios';
import {FILE_MODULE} from "./_prefix";
import request from '../utils/request';
import {axios} from '../utils/request'
import {MOCK} from "./_prefix";

/**
 *  添加文件 POST /upload
 * @param {*} payload:formData,直接放Body里
 * @returns
 */
export const UploadFile = payload => {
    return axios.post(`${FILE_MODULE}/file`,
        payload
        ,{
        headers:{
            'Content-Type': "multipart/form-data;"
            // 'Content-Type': "false",
            // 'Process-Data': 'false',
        }
    }).then((res) => {
        return res
    })
}


/**
 *  获得文件列表 GET /get/all
 * @param {*} userId 用户Id
 * @returns
 */
export const GetAllFile = userId => {
    return axios.get(`${FILE_MODULE}`, {
        params:{
            userId: userId
        }
    }).then( res => {
        return res;
    });
    // return axios.get(`${MOCK}/files:userId=1`, {
    //     }).then( res => {
    //         return res;
    //     });
}

// 直接返回数据
// return Promise.resolve({
//     "timestamp": 1649397417317,
//     "status": 200,
//     "data": [
//         {
//             "fileId": "1",
//             "fileName": "event_data"
//         }
//     ]
// })

/**
 *  获得文件具体信息 GET /get/detail
 * @param {*} fileId 文件Id
 * @returns
 */
export const getFileDetail = payload => {
    const {fileInfoId, userId} = payload;
    return axios.get(`${FILE_MODULE}/${fileInfoId}`,{
        params:{
            userId: userId
        }
    }).then( res => {
        return res;
    })
}

/**
 *  删除文件 GET /delete
 * @returns
 * @param fileInfoId
 */
export const deleteFile = fileInfoId => {
    return axios.delete(`${FILE_MODULE}/$fileInfoId}`).then( res => {
        return res;
    });
}

/**
 *  文件分析 GET /analysis/fields
 * @param {*} payload
 * @returns
 */
export const analysisFile = (fieldIds,funcId) => {
    console.log(fieldIds)
    fieldIds=JSON.parse(fieldIds)
    console.log(fieldIds)
    let url=`${FILE_MODULE}/analysis/fields?funcId=${funcId}`
    for(let i=0;i<fieldIds.length;i++){
        let fieldId=fieldIds[i]
        url+=`&fieldIds=${fieldId}`
    }
    console.log(url)
    return axios.get(url).then(res => {
        return res;
    });
}

/**
 *  获得文件描述信息 GET /get/detail
 * @returns
 * @param payload
 */
export const getFileDescribe = payload => {
    const {fileInfoId, userId} = payload;
    return axios.get(`${FILE_MODULE}/describe/${fileInfoId}`,{
        params:{
            userId: userId
        }
    }).then( res => {
        return res;
    })
    // return axios.get(`${MOCK}/files/:fileInfoId`).then( res => {
    //     return res;
    // })
}
